package com.bkgy.modular.tbdsjc621thickresult.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bkgy.modular.tbdsjc621thickresult.entity.JTbDsjC621thickResult;
import com.bkgy.modular.tbdsjc621thickresult.entity.SiData3;
import com.bkgy.modular.tbdsjc621thickresult.entity.TbDsjC621thickResult;
import com.bkgy.modular.tbdsjc621thickresult.service.TbDsjC621thickResultService;
import com.bkgy.sys.common.entity.JCommon;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.CodiUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 硅钢厚度1720产线厚度结果评价表控制器层
 *
 * @author 生成器生成
 * @date 2022-08-17 15:16:28
 */
@RestController
@RequestMapping("/tbDsjC621thickResult")
public class TbDsjC621thickResultController {

    @Autowired
    private TbDsjC621thickResultService tbDsjC621thickResultService;

    /**
     * 添加记录
     *
     * @param data userId 用户id
     * @param data sname 用户姓名
     */
    @CrossOrigin
    @RequestMapping(value = {"/insert"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData insertDataTbDsjC621thickResult(@RequestBody String data, @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tbDsjC621thickResultService.insertDataTbDsjC621thickResult(data, userId, CodiUtil.returnLm(sname));
    }

    /**
     * 根据主键删除对象
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/deleteOne"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData deleteDataTbDsjC621thickResultOne(@RequestBody String data) {
        try {
            JTbDsjC621thickResult jtbDsjC621thickResult = JSON.parseObject(data, JTbDsjC621thickResult.class);
            return tbDsjC621thickResultService.deleteDataTbDsjC621thickResultOne(jtbDsjC621thickResult.getIndocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 根据主键字符串删除多个对象
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/deleteMany"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData deleteDataSysUserMany(@RequestBody String data) {
        try {
            JTbDsjC621thickResult jtbDsjC621thickResult = JSON.parseObject(data, JTbDsjC621thickResult.class);
            return tbDsjC621thickResultService.deleteDataTbDsjC621thickResultMany(jtbDsjC621thickResult.getStr_indocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 修改记录
     *
     * @param data       json字符串
     * @param loginToken 请求头参数字符串对象
     */
    @CrossOrigin
    @RequestMapping(value = {"/update"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData updateDataTbDsjC621thickResult(@RequestBody String data, @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tbDsjC621thickResultService.updateDataTbDsjC621thickResult(data, userId, CodiUtil.returnLm(sname));
    }

    /**
     * 分页查看记录
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findByPage"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findDataTbDsjC621thickResultByPage(@RequestBody String data) {
        return tbDsjC621thickResultService.findDataTbDsjC621thickResultByPage(data);
    }

    /**
     * 列表导出功能
     * @param jsonObject
     * @param response
     */
    @PostMapping("/exportXlsx2")
    public void export(@RequestBody JSONObject jsonObject, HttpServletResponse response) {
        tbDsjC621thickResultService.export(jsonObject,response);
    }

    @CrossOrigin
    @RequestMapping(value = {"/findThickByVolumeNo621"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findThickByVolumeNo621(@RequestBody String data) {
        JSONObject jsonObject = JSONObject.parseObject(data);
        String data1 = jsonObject.getString("data");
        List<String> list = JSONObject.parseArray(data1, String.class);
        return tbDsjC621thickResultService.findThickByVolumeNo621(list);
    }


    @CrossOrigin
    @RequestMapping(value = {"/findThickByVolumeNo621Si3"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findThickByVolumeNo621Si3(@RequestBody String data) {
        JSONObject jsonObject = JSONObject.parseObject(data);
        String data1 = jsonObject.getString("data");
        List<String> list = JSONObject.parseArray(data1, String.class);
        try {
            List<SiData3> data3List = tbDsjC621thickResultService.findThickByVolumeNo621Si3(list);
            return ResultData.ResultDataSuccess(data3List);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf(null, "查询数据为空");
        }
    }

    /**
     * 根据主键查询单条记录
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findByIndocno"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findDataTbDsjC621thickResultByIndocno(@RequestBody String data) {
        return tbDsjC621thickResultService.findDataTbDsjC621thickResultByIndocno(data);
    }

    /**
     * 查看记录
     *
     * @return list 对象集合返回
     */
    @CrossOrigin
    @RequestMapping(value = {"/findAll"}, method = RequestMethod.POST)
    public List<TbDsjC621thickResult> findDataTbDsjC621thickResult() {
        return tbDsjC621thickResultService.findDataTbDsjC621thickResult();
    }


    @PostMapping("/exportXlsx")
    public void exportList(@RequestBody JSONObject jsonObject,HttpServletResponse response) {
        tbDsjC621thickResultService.exportList(jsonObject,response);
    }

    @PostMapping("/exportXlsxnew")
    public void exportListnew(@RequestBody JSONObject jsonObject,HttpServletResponse response) {
        tbDsjC621thickResultService.exportListnew(jsonObject,response);
    }
}
